home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / comp / lookstri.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  926 b   |  35 lines

  1. /*
  2.                            L O O K S T R I . C
  3.  
  4.     Lookup (and maybe enter) a string
  5. */
  6.  
  7. #include "iccomp.h"
  8.  
  9. static unsigned
  10.     n_allocated;
  11.  
  12. unsigned lookstring(s)
  13.     char *s;
  14. {
  15.     register unsigned
  16.         index;
  17.  
  18.     for (index = 0; index < n_strings; index++)
  19.         if (!strcmp(stringtab[index].string, s)) /* string found ? */
  20.             return (index);                      /* return string index */
  21.  
  22.     if (n_allocated == n_strings)           /* full table */
  23.         stringtab = xrealloc(stringtab,
  24.                              (n_allocated += 20) * sizeof(STRINGTAB_));
  25.  
  26.                                              /* set the string in memory */
  27.     stringtab[n_strings].string = xstrdup(s);
  28.     stringtab[n_strings].index = stringsize;
  29.  
  30.     stringsize += strlen(s) + 1;
  31.  
  32.     n_strings++;                            /* next free */
  33.     return (index);                         /* return string index */
  34. }
  35.